package hu.monitor.remoting;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class InterceptorInvocationHandler implements InvocationHandler {
	private final InterceptorChain interceptorChain;
	private final Class<?> remoteInterface;

	public InterceptorInvocationHandler(final InterceptorChain interceptorChain, final Class<?> remoteInterface) {
		this.interceptorChain = interceptorChain;
		this.remoteInterface = remoteInterface;
	}

	@Override
	public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
		final InvocationContext context = new InvocationContext(this.remoteInterface, method, args);
		return this.interceptorChain.processInvocation(context);
	}

}
